package com.lnsf.bookstore.system.shop.controller;

import com.github.pagehelper.PageInfo;
import com.lnsf.bookstore.common.dto.ResultSuccessDto;
import com.lnsf.bookstore.system.shop.vo.Shop;
import com.lnsf.bookstore.system.shop.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("shop")
public class ShopController {
    @Autowired
    private ShopService shopService;


    @RequestMapping("/v_list.do")
    public String list(HttpServletRequest request, ModelMap modelMap){
        System.out.println("shop界面.....");
        return "admin/shop/shop";
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    @ResponseBody
    //@RequiresPermissions("shop:list")
    public Object list(@RequestParam Map<String, Object> params){
        PageInfo<Shop> pageInfo = shopService.queryList(params);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("page",pageInfo);
        map.put("params",params);
        return map;
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("shop:info")
    @ResponseBody
    public Object info(@PathVariable("id") Integer id){
        Shop shop = shopService.queryObject(id);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("shop",shop);
        return map;
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("shop:save")
    @ResponseBody
    public Object save(@RequestBody Shop shop){
        shopService.save(shop);

        return new ResultSuccessDto("保存成功");
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("shop:update")
    @ResponseBody
    public Object update(@RequestBody Shop shop){
        shopService.update(shop);

        return new ResultSuccessDto("修改成功");
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("shop:delete")
    @ResponseBody
    public Object delete(@RequestBody Integer[] ids){
        shopService.deleteBatch(ids);

        return new ResultSuccessDto("删除成功");
    }

}
